package com.darrenchan.leetcode;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @Desc
 * @Author chenchi03
 * @CreateTime 2019-12-27 19:14
 */
public class Q559 {
    public int maxDepth(Node root) {
        if(root == null){
            return 0;
        }

        Queue<Node> queue = new LinkedList<>();
        queue.add(root);
        int distance = 0;

        while (!queue.isEmpty()){
            int size = queue.size();
            for (int i = 0; i < size; i++) {
                root = queue.poll();
                for (Node child : root.children) {
                    if(child != null){
                        queue.add(child);
                    }
                }
            }
            distance++;
        }
        return distance;
    }
}
